/**
 * @Author : 15208438782
 * @Timestamp : 2017-09-18
 */
var app=sm("do_App");
var nf = sm("do_Notification");
var page=sm("do_Page");
var btn_back = ui("do_ALayout_back");
var config=require("config");
var do_webviewalt=ui("do_ALayout_8");
//用于等待登录的过程
var cache=sm("do_DataCache");
var userinfo=cache.loadData("userinfo");
var do_ALayout_root=ui("do_ALayout_8");
//用于等待登录的过程
//初始化隐藏遮盖
do_ALayout_root.add("loadingUI", "source://view/loadingUI.ui", 0, 0);

page.on("loaded", function(data, e) {
	var loadingUI = ui("loadingUI");
	loadingUI.visible = true;
	var nowdate=new Date();
	var olddate=nowdate.getTime();
	app.fire("tologin",{times:olddate,pagesize:2});
	var http = mm("do_Http");
	http.method = "POST";  
	http.timeout = 30000; 
	http.contentType = "application/json"; 
	http.url = config.baseUrl+"getBuessTypeBalance"; 
	http.body = JSON.stringify({usernum:userinfo.usernum,userId:userinfo.userid}); 
	http.on("success", function(data) {

		if(data.result==1 && data.data.typenum.length>0){	

			do_webviewalt.add("classifywebview", "source://view/money/classifywebview.ui", 0, 1);
			var classifywebview=ui("classifywebview");
			var hashdata = mm("do_HashData");
			hashdata.addData({
				"chartdata" : data.data
			});
			classifywebview.bindData(hashdata);
			classifywebview.refreshData();
			loadingUI.visible = false;
		}
		else if(data.result==3045){	
			loadingUI.visible = false;
			 app.closePage({data:"帐号可能被其它终端登录，请重新登录", animationType:"", layer:2});	
			 cache.saveData("userinfo", "");
		}
		else{
			loadingUI.visible = false;
			nf.toast(data.msg || "失败");
		}
	});
	http.on("fail", function(data) {
		loadingUI.visible = false;
		nf.toast(data.msg || "网络超时");
		
	});
	http.request();
	
	
});

btn_back.on("touch", function() {
	app.closePage();
});

